package com.ss.android.article.base.feature.detail.presenter;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.ColorFilter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.b.ImpressionHelper;
import com.ss.android.action.b.b;
import com.ss.android.action.b.BaseDetailAdapter;
import com.ss.android.action.b.FeedViewHolder;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.common.app.LifeCycleMonitor;
import com.ss.android.image.AsyncImageView;
import com.ss.android.j.ClickableBackgroundCompat;

import java.util.List;

public final class v extends BaseDetailAdapter implements LifeCycleMonitor {
    public List d;
    public boolean e;
    public String f;
    private Context g;
    private Resources h;
    private LayoutInflater i;
    private Article j;
    private int k;
    private int l;
    private int m;

    public v(Context arg4, List arg5, Article arg6) {
        this.d = arg5;
        this.j = arg6;
        this.g = arg4;
        this.m = 2;
        this.h = arg4.getResources();
        this.i = LayoutInflater.from(arg4);
        this.k = (UIUtils.getScreenWidth(this.g) - this.h.getDimensionPixelOffset(R.dimen.pic_detail_related_picture_horizontal_gap)) / 2;
        this.l = ((int) (0.654088f * (((float) this.k))));
    }

    private Article a(int arg2) {
        Article v0;
        if (this.d == null) {
            v0 = null;
        } else {
            v0 = (Article) this.d.get(arg2);
        }

        return v0;
    }

    public final boolean a() {
        boolean v0 = !super.a() || !this.e ? false : true;
        return v0;
    }

    public final boolean a(int arg2, FeedViewHolder arg3) {
        boolean v0 = !super.a(arg2, arg3) || !this.e ? false : true;
        return v0;
    }

    public final b d() {
        if (this.b == null && !android.support.design.a.isTextEmpty(this.f)) {
            this.b = ImpressionHelper.getInstance().a(12, this.f, null);
        }

        return this.b;
    }

    public final void onDestroy() {
        if (this.b != null && !android.support.design.a.isTextEmpty(this.f)) {
            ImpressionHelper.getInstance().a(this.b, this.f);
        }
    }

    public final void onResume() {
        this.a = true;
        if (this.getCount() > 0) {
            this.g_();
        }
    }

    public final void onPause() {
        this.f();
        this.a = false;
    }

    public final int getCount() {
        return this.d == null ? 0 : this.d.size();
    }

    public final Object getItem(int arg2) {
        return this.a(arg2);
    }

    public final long getItemId(int arg3) {
        return ((long) arg3);
    }

    public final View getView(int position, View convertView, ViewGroup arg13) {
        boolean v0_4;
        w v1;
        if (convertView == null) {
            convertView = this.i.inflate(com.ss.android.article.browser.R.layout.picture_detail_related_image_item, null);
            v1 = new w(this.g, this.m);
            v1.mRelatedImageView = convertView.findViewById(com.ss.android.article.browser.R.id.related_imageview);
            v1.mTitleView = convertView.findViewById(com.ss.android.article.browser.R.id.title_view);
            v1.mTitleView.setLines(2);
            convertView.setTag(v1);
            ViewGroup.LayoutParams v0 = v1.mRelatedImageView.getLayoutParams();
            v0.width = this.k;
            v0.height = this.l;
            v1.mRelatedImageView.setLayoutParams(v0);
        } else {
            Object v0_1 = convertView.getTag();
            if (v0_1 != null) {
                v1 = (w) v0_1;
            } else {
                return convertView;
            }
        }
        Article v4 = this.a(position);
        if (v4 != null) {
            ((w) v1).mRoot = convertView.findViewById(com.ss.android.article.browser.R.id.root);
            ((w) v1).mTitleView = convertView.findViewById(com.ss.android.article.browser.R.id.title_view);
            ((w) v1).mRelatedImageView = convertView.findViewById(com.ss.android.article.browser.R.id.related_imageview);
            ((w) v1).mRoot.setOnClickListener(((w) v1).y);
            long v2 = this.j == null ? 0 : this.j.groupId;
            if (v4 != null && v4.groupId > 0) {
                ((w) v1).r = v4;
                ((w) v1).w = v2;
                if (((w) v1).r != null) {
                    if (((w) v1).x == 2) {
                        ((w) v1).mTitleView.setText(((w) v1).r.title);
                    } else if (((w) v1).x == 1) {
                        String v0_2 = ((w) v1).r.title;
                        if (!TextUtils.isEmpty(((w) v1).r.title) && (((w) v1).r.title.contains(" "))) {
                            StringBuilder v0_3 = new StringBuilder();
                            v0_3.append(((w) v1).r.title).append(" ");
                            v0_2 = v0_3.toString();
                        }

                        if (((w) v1).r.tags == null || (((w) v1).r.tags.isEmpty())) {
                            ((w) v1).mTitleView.setText(((CharSequence) v0_2));
                        } else {
                            ((w) v1).mTitleView.setText(android.support.design.a.a(v0_2, ((w) v1).r.tags, ((w) v1).u.getColor(com.ss.android.article.browser.R.color.update_comment_more_text_selector)));
                        }

                        TextView v2_1 = ((w) v1).mTitleView;
                        v0_4 = ((w) v1).r.clickTimestamp <= 0 ? true : false;
                        v2_1.setEnabled(v0_4);
                    }
                }

                NightModeAsyncImageView v0_5 = ((w) v1).mRelatedImageView;
                if (v0_5 != null && v4 != null && v4.middleImage != null) {
                    android.support.design.a.setImage(((AsyncImageView) v0_5), v4.middleImage);
                }

                if (((w) v1).x != 2) {
                    int v0_6 = ((w) v1).t.mFontSizePref;
                    if (v0_6 < 0 || v0_6 > 3) {
                        v0_6 = 0;
                    }

                    ((w) v1).mTitleView.setTextSize(((float) y.a[v0_6]));
                }

                if (((w) v1).x == 2) {
                } else if (((w) v1).v == AppData.isNightMode()) {
                } else {
                    ((w) v1).v = AppData.isNightMode();
                    v0_4 = ((w) v1).v;
                    ClickableBackgroundCompat.setClickableBackground(((w) v1).mRoot, v0_4);
                    if (((w) v1).r.clickTimestamp > 0) {
                        ((w) v1).mTitleView.setTextColor(((w) v1).u.getColor(com.ss.android.article.browser.R.color.c1));
                    } else {
                        ((w) v1).mTitleView.setTextColor(((w) v1).u.getColor(com.ss.android.article.browser.R.color.ssxinzi2));
                    }

                    UIUtils.setBackgroundResource(((w) v1).mRelatedImageView, R.color.t);
                    ColorFilter v0_7 = v0_4 ? TTUtils.getNightModeColorFilter() : null;
                    ((w) v1).mRelatedImageView.setColorFilter(v0_7);
                }
            }
            ((w) v1).a(37, android.support.design.a.a(v4.groupId, v4.itemId, null));
            if (!this.a()) {
                return convertView;
            }
            this.a(v1);
        }
        return convertView;
    }

    public final void onStop() {
    }
}

